﻿using System;
using System.Linq;
using System.Windows.Shapes;
using Boxi.EventArguments;
using Boxi.Model;
using System.Windows.Controls;

namespace Boxi.ViewModel
{
    public class PointView
    {
        #region Fields
        #endregion
        #region Events

        #endregion

        #region Properties
        public Byte PointID
        {
            get;
            private set;
        }

        /// <summary>
        /// 
        /// </summary>
        public GameView Game
        {
            get;
            private set;
        }

        /// <summary>
        /// 
        /// </summary>
        public Rectangle SquareUI
        {
            get;
            set;
        }

        /// <summary>
        /// 
        /// </summary>
        public TextBlock Text
        {
            get;
            set;
        }
        #endregion
        #region Constructors
        /// <summary>
        /// 
        /// </summary>
        /// <param name="column"></param>
        /// <param name="row"></param>
        /// <param name="squareUI"></param>
        public PointView(GameView game, Byte index, Rectangle squareUI, TextBlock  text)
        {
            Game = game;
            PointID = index;
            SquareUI = squareUI;
            Text = text;
        }
        #endregion
        #region Methods
      
      
        #endregion
        #region Envet Handlers
        public void MoveAssigned(object sender, PointAssignedEventArgs e)
        {
            MoveView moveView = (MoveView)sender;
            MoveHistoryModel moveHistory = Game.MoveHistory[Game.MoveOptions[moveView.MoveID - 1].MoveMadeOrder - 1];
            if (moveHistory.Points.Contains(PointID) && moveHistory.PlayerID > 0)
            {
                if (Game.Theme == GameModel.ThemeType.Arcade)
                {
                    SquareUI.Fill = Game.Players[moveHistory.PlayerID - 1].Color;
                    SquareUI.Opacity = 1d;
                }
                else
                {
                    Text.Text = Game.Players[moveHistory.PlayerID - 1].PlayerData.Name.Substring(0, 1);
                    Text.Text += Game.Players[moveHistory.PlayerID - 1].PlayerData.Name.Substring(Game.Players[moveHistory.PlayerID - 1].PlayerData.Name.Length - 1, 1);
                }
                e.PointAssigned = true;
            }
        }
        #endregion
        #region Methods

        #endregion
    }
}
